package com.jade.journal.appender;

import com.jade.journal.AbstractAppender;
import com.jade.journal.JournalAppender;
import com.jade.journal.JournalEvent;
import com.jade.journal.desc.JournalDesc;

/**
 * 多个Appender组成的Appender.
 *
 * @author sky
 * @version 1.0 14-9-23 上午9:08
 */
public class MultiAppender extends AbstractAppender
{
    private JournalAppender[] appenders;

    public MultiAppender(JournalDesc desc, JournalAppender[] appenders)
    {
        super("multi", desc, null);
        this.appenders = appenders;
    }

    @Override
    public void init(JournalEvent event)
    {
        super.init(event);
        for (JournalAppender appender : appenders) {
            appender.init(event);
        }
    }

    public void append(JournalEvent... events)
    {
        for (JournalAppender appender : appenders) {
            try {
                appender.append(events);
            }
            catch (Throwable t) {
                log.error("Can't append journal:", t);
            }
        }
    }
}
